<?php

namespace App\Http\Controllers;

use App\Common\Constant\Params;
use App\Common\Constant\Status;
use App\Libs\Filter\Filter;
use App\Models\Goods;
use App\Models\Merchant;
use App\Services\ICouponService;
use App\Services\IMerchantService;
use App\Services\ISystemService;
use Illuminate\Http\Request;

/**
 * 商家相关
 * Class MerchantController
 * @package App\Http\Controllers
 */
class MerchantController extends BaseController
{
    /**
     * 所有商家
     * @param Request $request
     */
    public function all(Request $request,IMerchantService $merchantService,ICouponService $couponService)
    {
        $filter = Filter::instance()
            ->HTML('用户名：')
            ->input('me_username')
            ->HTML('手机号：')
            ->input('me_phone')
            ->HTML('用户类型：')
            ->select('me_category',array(''=>'请选择')+Params::$MERCHANT_TYPE,null,array('style'=>'width:150px'))
            ->HTML('下单情况：')
            ->select('orders',array(''=>'请选择')+Params::$MERCHANT_SERVICE_TYPE,null,array('style'=>'width:150px'))
            ->br()->br()
            ->HTML('定价下单：')
            ->select('merchant_status',array(''=>'请选择')+Params::$ORDER_MERCHANT_STATUS,null,array('style'=>'width:150px'))
            ->HTML('账户封号：')
            ->select('me_status',array(''=>'请选择')+Params::$MERCHANT_STATUS,null,array('style'=>'width:150px'))
            ->HTML('注册时间：')
            ->date('me_add_time')
            ->br()->br()
            ->reset()->submit();
        if ($filter->is_filtering()){
            $list = $merchantService->all($filter->get_where());
        }else{
            $list = $merchantService->all();
        }

        $coupon_list = $couponService->getCoupleList();

        return view('merchant/all',['list'=>$list,'filter'=>$filter,'coupon_list'=>$coupon_list]);
    }

    /**
     * 封号
     * @param Request $request
     */
    public function disable($merchant_id,Request $request,IMerchantService $merchantService)
    {
        $merchantService->disable($merchant_id);
        return back();
    }

    /**
     * 解封
     * @param Request $request
     */
    public function enable($merchant_id,Request $request,IMerchantService $merchantService)
    {
        $merchantService->enable($merchant_id);
        return back();
    }

    /**
     * 发放的优惠券列表
     * @param Request $request
     */
    public function coupon($merchant_id,Request $request,IMerchantService $merchantService)
    {
        $list = $merchantService->couponList($merchant_id);
        return view('merchant/coupon',['list'=>$list]);
    }

    /**
     * 商家的商品列表
     * @param Request $request
     */
    public function goods($merchant_id,Request $request,IMerchantService $merchantService)
    {
        $list = $merchantService->goodsList($merchant_id);
        return view('merchant/goods',['list'=>$list]);
    }

    /**
     * 删除商品
     * @param Request $request
     */
    public function delGoods(Goods $goods,Request $request)
    {
        $goods->delete();
        return back();
    }

    /**
     * 申请定价下单用户
     * @param Request $request
     */
    public function applyPriced(Request $request,IMerchantService $merchantService)
    {
        $list = $merchantService->applyPricedList();
        return view('merchant/applyPricedList',['list'=>$list]);
    }


}
